# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>

_pkgname=openFPGALoader
pkgname=openfpgaloader
pkgver=0.11.0
pkgrel=1
pkgdesc='Universal utility for programming FPGA'
arch=('loong64' 'x86_64')
url='https://github.com/trabucayre/openFPGALoader'
license=('Apache2')
depends=('libftdi' 'libftdi-compat' 'libhidapi-hidraw.so' 'libudev.so')
makedepends=('cmake' 'libusb' 'systemd')
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha512sums=('cffc5f9ae0ffd75c7b7954dc19e348c80c2c847141879b6dfac06efc22fc0f574d9352cbd748553275077364a2086b00af67b5ea11130a6eea3e6f32e01f3f42')

prepare() {
  sed -i 's|MODE="664", GROUP="plugdev"|MODE="666"|g' $_pkgname-$pkgver/99-openfpgaloader.rules
}

build() {
  mkdir -p $_pkgname-$pkgver/build
  cd $_pkgname-$pkgver/build

  export CFLAGS+=" ${CPPFLAGS}"
  export CXXFLAGS+=" ${CPPFLAGS}"

  cmake .. \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_BUILD_TYPE=None \
    -DENABLE_UDEV=True \
    -DENABLE_CMSISDAP=True

  make
}

package() {
  cd $_pkgname-$pkgver/build

  make DESTDIR="$pkgdir" install

  install -Dm 644 ../99-openfpgaloader.rules "$pkgdir"/usr/lib/udev/rules.d/99-openfpgaloader.rules
}

